package com.effective;

import java.util.Arrays;
import java.util.Collection;

public class OperationMain {
	public static void main(String[] args) {
		double x = 12;
		double y = 2;
		test1(ExtendedOperation.class, x, y);
		test2(Arrays.asList(ExtendedOperation.values()), x, y);
	}

	private static <T extends Enum<T> & Operation> void test1(Class<T> opSet, double x, double y) {
		for (Operation op : opSet.getEnumConstants())
			System.out.printf("%f %s %f = %f%n", x, op, y, op.apply(x, y));
	}
	
	private static <T extends Enum<T> & Operation> void test2(Collection<? extends Operation> opSet, double x, double y) {
		for (Operation op : opSet)
			System.out.printf("%f %s %f = %f%n", x, op, y, op.apply(x, y));
	}
}/**
Output:
12.000000 ^ 2.000000 = 144.000000
12.000000 % 2.000000 = 0.000000
12.000000 ^ 2.000000 = 144.000000
12.000000 % 2.000000 = 0.000000
*/
